package cn.iocoder.yudao.module.shop.dal.mysql.crossorder;

import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.shop.dal.dataobject.crossorder.ShopCrossOrderDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.shop.controller.admin.crossorder.vo.*;

/**
 * 跨店铺 Mapper
 *
 * @author 曹建伟
 */
@Mapper
public interface ShopCrossOrderMapper extends BaseMapperX<ShopCrossOrderDO> {

    default PageResult<ShopCrossOrderDO> selectPage(ShopCrossOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ShopCrossOrderDO>()
                .eqIfPresent(ShopCrossOrderDO::getMemberId, reqVO.getMemberId())
                .likeIfPresent(ShopCrossOrderDO::getMemberName, reqVO.getMemberName())
                .eqIfPresent(ShopCrossOrderDO::getUserId, reqVO.getUserId())
                .likeIfPresent(ShopCrossOrderDO::getUserName, reqVO.getUserName())
                .eqIfPresent(ShopCrossOrderDO::getSourceTenantId, reqVO.getSourceTenantId())
                .eqIfPresent(ShopCrossOrderDO::getTargetTenantId, reqVO.getTargetTenantId())
                .betweenIfPresent(ShopCrossOrderDO::getOrderTime, reqVO.getOrderTime())
                .betweenIfPresent(ShopCrossOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopCrossOrderDO::getId));
    }

    default List<ShopCrossOrderDO> selectList(ShopCrossOrderExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ShopCrossOrderDO>()
                .eqIfPresent(ShopCrossOrderDO::getMemberId, reqVO.getMemberId())
                .likeIfPresent(ShopCrossOrderDO::getMemberName, reqVO.getMemberName())
                .eqIfPresent(ShopCrossOrderDO::getUserId, reqVO.getUserId())
                .likeIfPresent(ShopCrossOrderDO::getUserName, reqVO.getUserName())
                .eqIfPresent(ShopCrossOrderDO::getSourceTenantId, reqVO.getSourceTenantId())
                .eqIfPresent(ShopCrossOrderDO::getTargetTenantId, reqVO.getTargetTenantId())
                .betweenIfPresent(ShopCrossOrderDO::getOrderTime, reqVO.getOrderTime())
                .betweenIfPresent(ShopCrossOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopCrossOrderDO::getId));
    }

    default List<ShopCrossOrderDO> selectListSourceByTenantId(Long tenantId, LocalDateTime startTime, LocalDateTime endTime){
        LambdaQueryWrapperX<ShopCrossOrderDO> query1 = new LambdaQueryWrapperX<ShopCrossOrderDO>()
                .betweenIfPresent(ShopCrossOrderDO::getOrderTime, startTime, endTime)
                .eq(ShopCrossOrderDO::getSourceTenantId, tenantId);

        return selectList(query1);
    }

    default List<ShopCrossOrderDO> selectListTargetByTenantId(Long tenantId, LocalDateTime startTime, LocalDateTime endTime){
        LambdaQueryWrapperX<ShopCrossOrderDO> query1 = new LambdaQueryWrapperX<ShopCrossOrderDO>()
                .betweenIfPresent(ShopCrossOrderDO::getOrderTime, startTime, endTime)
                .eq(ShopCrossOrderDO::getTargetTenantId, tenantId);

        return selectList(query1);
    }
}
